home *** CD-ROM | disk | FTP | other *** search
/ Technotools / Technotools (Chestnut CD-ROM)(1993).ISO / lang_c / abbrev4 / ablookup.m < prev   
Text File  |  1989-11-16  |  5KB  |  129 lines

  1. ;**************************************************************************
  2. ;*                                                                                                  *
  3. ;*     ABLOOKUP.CB                                                                              *
  4. ;*                                                                                               *
  5. ;*     This contains the utility files used both by "abbrev" and              *
  6. ;*     "suffix".  Either package may be used alone in conjunction              *
  7. ;*     with this file, and suffix no longer requires the full                  *
  8. ;*     abbrev to be used.                                                                  *
  9. ;*                                                                                               *
  10. ;*     Larry DeMar   10-19-89.                                                              *
  11. ;*                                                                                                  *
  12. ;**************************************************************************
  13. ;*                                                                                                  *
  14. ;*      AB_LOOKUP                                                                              *
  15. ;*                                                                                               *
  16. ;*      This is called to look up a string in an abbreviation file.          *
  17. ;*                                                                                               *
  18. ;*      Parameter 0 = file part of file name to look in                          *
  19. ;*      Parameter 1 = string to lookup                                                  *
  20. ;*      Parameter 2 = global buffer id of system buffer we're using          *
  21. ;*      Parameter 3 = filename for system buffer                                      *
  22. ;*                                                                                               *
  23. ;*      If parameter 2 is non-zero, then it is the id of a                      *
  24. ;*      system buffer containing the lookup file.  Else, we                      *
  25. ;*      create the system buffer.  Read the lookup file in,                      *
  26. ;*      and put the new buffer id to parameter 2.                                  *
  27. ;*                                                                                               *
  28. ;*      If the string is found to start in column 1 of the                      *
  29. ;*      lookup file, then the "return string" is on the                          *
  30. ;*      rest of the line in the file.    The return string                          *
  31. ;*      is put back to parameter 1.                                                      *
  32. ;*                                                                                               *
  33. ;*      This returns TRUE of FALSE based on whether the lookup                  *
  34. ;*      succeeded.                                                                              *
  35. ;*                                                                                                  *
  36. ;**************************************************************************
  37. (macro ab_lookup
  38.    (
  39.       (string file_part
  40.               abbreviation
  41.               my_search_string
  42.               sys_file_name
  43.       )
  44.       (int orig_buffer
  45.            system_id
  46.            return_code
  47.       )
  48.       (get_parm 0 file_part)
  49.       (get_parm 1 abbreviation)
  50.       (get_parm 2 system_id)
  51.       (get_parm 3 sys_file_name)
  52.       (= orig_buffer (inq_buffer))
  53.       (if system_id   ; abbrev file in buffer?
  54.          (set_buffer system_id)    ; yep...go there
  55.       ;else
  56.          (
  57.             (= system_id (create_sys_buf file_part sys_file_name))   ; no...create it.
  58.             (put_parm 2 system_id)   ; and pass it back.
  59.          )
  60.       )
  61.       (top_of_buffer)
  62.       (sprintf my_search_string "<%s[ \t]\\c" abbreviation)
  63.       (if (= return_code (search_fwd my_search_string 1 0))
  64.          (put_parm 1 (trim (ltrim (read))))
  65.       )
  66.       (set_buffer orig_buffer)
  67.       (return return_code)
  68.    )
  69. )
  70. ;**************************************************************************
  71. ;*                                                                                                  *
  72. ;*      CREATE_SYS_BUF                                                                      *
  73. ;*                                                                                               *
  74. ;*      This is called to create the system buffer and read in                  *
  75. ;*      the abbreviation file.                                                              *
  76. ;*                                                                                               *
  77. ;*      It returns the id of the buffer it creates.                                  *
  78. ;*                                                                                                  *
  79. ;**************************************************************************
  80. (macro create_sys_buf
  81.    (
  82.       (int buf_id)
  83.       (string file_part
  84.               buffer_name
  85.       )
  86.       (get_parm 0 file_part)
  87.       (get_parm 1 buffer_name)
  88.       (= buf_id (create_buffer "abbrev_buf" buffer_name 1))
  89.       (set_buffer buf_id)
  90.       (read_file (get_abbrev_file file_part))   ; read in the file
  91.       (return buf_id)
  92.    )
  93. )
  94. ;**************************************************************************
  95. ;*                                                                                                  *
  96. ;*      GET_ABBREV_FILE                                                                      *
  97. ;*                                                                                               *
  98. ;*      This is called to return the full path of the abbrev                      *
  99. ;*      directory file.                                                                      *
  100. ;*                                                                                               *
  101. ;*              1) if BABBREV is in environment, then it is                          *
  102. ;*                  used as the path.                                                      *
  103. ;*                                                                                               *
  104. ;*              2) if BPATH is in environment, then it is                          *
  105. ;*                  used as the path.                                                      *
  106. ;*                                                                                               *
  107. ;*              3) otherwise "C:\" is used as the path.                              *
  108. ;*                                                                                                  *
  109. ;**************************************************************************
  110. (macro get_abbrev_file
  111.    (
  112.       (string abbrev_path
  113.               file_part
  114.       )
  115.       (int semi_spot)
  116.       (get_parm 0 file_part)
  117.       (if (== (= abbrev_path (inq_environment "BABBREV")) "")
  118.          (if (== (= abbrev_path (inq_environment "BPATH")) "")
  119.             (= abbrev_path "c:")
  120.          ;else
  121.             (if (= semi_spot (rindex abbrev_path ";"))
  122.                (= abbrev_path (substr abbrev_path (+ semi_spot 1)))
  123.             )
  124.          )
  125.       )
  126.       (return (+ (trim (ltrim abbrev_path)) (+ "\\" file_part)))
  127.    )
  128. )
  129.